<%@page import="com.mvc.ProjectUtils"%>
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ include file="/pages/common/header.jsp"%>
</head>
<body>
	<div class="contentBody contentborder">
		<div class="tab-pane tabPane" id="tabPane">
            <div id="message"><%=message %></div>
			<div class="tab-page" id="tabPage1">
				 <h1 class="tab">用户信息</h1>
 				 <div class="contentborder tableForm">
                	 <jdf:form bean="entity" scope="request">
						<form action="<%=dynamicDomain%>/extendUser/save" method="post" onsubmit="prepare();">
							<input type="hidden" name="id" id="id">
							<input type="hidden" name="objectId">
							<input type="hidden" name="companyIds" id="companyIds">
							<input type="hidden" name="companyId1s" id="companyId1s">
							<input type="hidden" name="companyId2s" id="companyId2s">
							<input type="hidden" name="noticeTypes" id="noticeTypes">
							 <table class="inputTable">
			                 	<tr>
									<td class="label cancelBorderLeft">
										<label for="loginName">登录名：</label>
									</td>
									<td class="content ">
										<input type="text" name="loginName">
									</td>
									<td class="label">
										<label for="userName">用户名：</label>
									</td>
									<td class="content">
										<input type="text" name="userName">
									</td>
								</tr>
								<c:choose>
                                <c:when test="${not empty entity.id && entity.type=='10'}">
                                    <input type="hidden" name="email" size="70"  value="">
                                </c:when>
                                <c:otherwise>
                                <tr>
                                    <td class="label cancelBorderLeft">
                                        <label for="email">电子邮件：</label>
                                    </td>
                                    <td class="content"  colspan="3">
                                        <input type="text" name="email" size="70"  title="多个邮件地址之间用分号(;)分割">
                                    </td>
                                </tr>
                                <tr>
                                    <td class="label cancelBorderLeft">
                                        <label for="phone">电话：</label>
                                    </td>
                                    <td class="content" colspan="3">
                                        <input type="text" name="phone">
                                    </td>
                                </tr>
                                </c:otherwise>
                                </c:choose>
								<tr>
									<td class="label cancelBorderLeft">
										<label for="type">用户类型：</label>
									</td>
									<td class="content" id="type">
									   <c:choose>
                                            <c:when test="${not empty entity.id && entity.type=='10'}">
										      <input type="hidden" name="type" value="${entity.type}">
										      &nbsp;<jdf:dictionaryName dictionaryId="104" value="${entity.type }"/>
											</c:when>
											<c:otherwise>
											  <select name="type" id="typeSelect">
											      <option value="">请选择</option>
		                                          <jdf:select dictionaryId="104" valid="true"/>
		                                      </select>
											</c:otherwise>
										</c:choose>
									</td>
									<td class="label pass">
										<label for="password">密码：</label>
									</td>
									<td class="content pass">
										<input type="password" name="password">
									</td>
			                 	</tr>
			                 	<tr>
			                 	   <td class="label cancelBorderLeft">
                                        <label for="remark">签名：</label>
                                    </td>
                                    <td class="content">
                                        <input type="text" name="remark">
                                    </td>
                                    <td class="content" colspan="2">
                                         <c:if test="${not empty  entity.remark}">
                                            <img src="<%=ProjectUtils.getFullCssThemePath() %>images/system/personal/${entity.remark}">
                                        </c:if>
                                    </td>
			                 	</tr>
			                 	<tr>
                                    <td class="label cancelBorderLeft">
                                        <label for="sex">状态：</label>
                                    </td>
                                    <td class="content" colspan="3">
                                        <select name="sex">
                                            <jdf:select dictionaryId="111"/>
                                        </select>
                                    </td>
                                </tr>
			                 	<c:if test="${empty entity.id || entity.type!='10'}">
			                 	<tr>
			                 	   <td class="label cancelBorderLeft">
                                        <label for="remark">所属公司：</label>
                                    </td>
                                    <td class="content" colspan="3">
                                        <table width="100%">
                                           <c:forEach varStatus="num" var="item" items="${companies}">
                                                 <tr>
                                                      <c:set var="_check" value="" />
                                                       <c:forEach varStatus="num" var="item1" items="${selected}">
                                                          <c:if test="${item1.companyId ==item.objectId}">
                                                              <c:set var="_check" value="checked" />
                                                          </c:if>
                                                       </c:forEach>
                                                      <td style="width: 5%">&nbsp;<input type="checkbox" value="${item.objectId}" id="c_${item.objectId}" name="company"  ${_check} style="vertical-align: middle;"></td>
                                                      <td>&nbsp;<label for="c_${item.objectId}" >${item.name}</label></td>
                                                </tr>
                                            </c:forEach>
                                        </table>
                                    </td>
			                 	</tr>
			                 	<tr>
			                 	   <td class="label cancelBorderLeft">
                                        <label for="notice">审批通知：</label>
                                    </td>
                                    <td class="content" colspan="3">
                                        <table width="100%">
                                           <tr>
                                                 <c:set var="_check" value="" />
                                                  <c:forEach varStatus="num" var="item1" items="${userNotices}">
                                                     <c:if test="${item1.type ==1}">
                                                         <c:set var="_check" value="checked" />
                                                     </c:if>
                                                  </c:forEach>
                                                 <td style="width: 5%">&nbsp;<input type="checkbox" value="1" id="notice_1" name="userNotice"  ${_check} style="vertical-align: middle;"></td>
                                                 <td>&nbsp;<label for="notice_1" >订单审核</label></td>
                                           </tr>
                                           <tr>
                                                 <c:set var="_check" value="" />
                                                  <c:forEach varStatus="num" var="item1" items="${userNotices}">
                                                     <c:if test="${item1.type ==10}">
                                                         <c:set var="_check" value="checked" />
                                                     </c:if>
                                                  </c:forEach>
                                                 <td>&nbsp;<input type="checkbox" value="10" id="notice_10" name="userNotice"  ${_check} style="vertical-align: middle;"></td>
                                                 <td>&nbsp;<label for="notice_10" >采购审核</label></td>
                                           </tr>
                                           <tr>
                                                 <c:set var="_check" value="" />
                                                  <c:forEach varStatus="num" var="item1" items="${userNotices}">
                                                     <c:if test="${item1.type ==20}">
                                                         <c:set var="_check" value="checked" />
                                                     </c:if>
                                                  </c:forEach>
                                                 <td>&nbsp;<input type="checkbox" value="20" id="notice_20" name="userNotice"  ${_check} style="vertical-align: middle;"></td>
                                                 <td>&nbsp;<label for="notice_20" >费用申请审核</label></td>
                                           </tr>
                                           <tr>
                                                 <c:set var="_check" value="" />
                                                  <c:forEach varStatus="num" var="item1" items="${userNotices}">
                                                     <c:if test="${item1.type ==30}">
                                                         <c:set var="_check" value="checked" />
                                                     </c:if>
                                                  </c:forEach>
                                                 <td>&nbsp;<input type="checkbox" value="30" id="notice_30" name="userNotice"  ${_check} style="vertical-align: middle;"></td>
                                                 <td>&nbsp;<label for="notice_30" >报价单审核</label></td>
                                           </tr>
                                           <tr>
                                                 <c:set var="_check" value="" />
                                                  <c:forEach varStatus="num" var="item1" items="${userNotices}">
                                                     <c:if test="${item1.type ==40}">
                                                         <c:set var="_check" value="checked" />
                                                     </c:if>
                                                  </c:forEach>
                                                 <td>&nbsp;<input type="checkbox" value="40" id="notice_40" name="userNotice"  ${_check} style="vertical-align: middle;"></td>
                                                 <td>&nbsp;<label for="notice_40" >商业发票审核</label></td>
                                           </tr>
                                        </table>
                                    </td>
			                 	</tr>
			                 	</c:if>
			                 	<c:if test="${entity.type==3||entity.type==5}">
                                <tr>
                                   <td class="label cancelBorderLeft">
                                        <label for="remark">应收财务权限：</label>
                                    </td>
                                    <td class="content" colspan="3">
                                        <table width="100%">
                                           <c:forEach varStatus="num" var="item" items="${companies}">
                                                 <tr>
                                                      <c:set var="_check" value="" />
                                                       <c:forEach varStatus="num" var="item1" items="${finances}">
                                                          <c:if test="${item1.companyId ==item.objectId && item1.type=='1'}">
                                                              <c:set var="_check" value="checked" />
                                                          </c:if>
                                                       </c:forEach>
                                                      <td style="width: 5%">&nbsp;<input type="checkbox" value="${item.objectId}" id="c_${item.objectId}_1" name="company1"  ${_check} style="vertical-align: middle;"></td>
                                                      <td>&nbsp;<label for="c_${item.objectId}_1" >${item.name}</label></td>
                                                </tr>
                                            </c:forEach>
                                        </table>
                                    </td>
                                </tr>
                                <tr>
                                   <td class="label cancelBorderLeft">
                                        <label for="remark">应付财务权限：</label>
                                    </td>
                                    <td class="content" colspan="3">
                                        <table width="100%">
                                           <c:forEach varStatus="num" var="item" items="${companies}">
                                                 <tr>
                                                      <c:set var="_check" value="" />
                                                       <c:forEach varStatus="num" var="item1" items="${finances}">
                                                          <c:if test="${item1.companyId ==item.objectId && item1.type=='2'}">
                                                              <c:set var="_check" value="checked" />
                                                          </c:if>
                                                       </c:forEach>
                                                      <td style="width: 5%">&nbsp;<input type="checkbox" value="${item.objectId}" id="c_${item.objectId}_2" name="company2"  ${_check} style="vertical-align: middle;"></td>
                                                      <td>&nbsp;<label for="c_${item.objectId}_2" >${item.name}</label></td>
                                                </tr>
                                            </c:forEach>
                                        </table>
                                    </td>
                                </tr>
                                </c:if>
			                 	<tr>
                                	<td class="bottomLabel" colspan="4">
                                		<div class="right">
											<button type="submit">提交</button>
											<button type="button" onclick="intoResetPassword()" id="resetPassaord">重置密码</button>
											<button type="button" onclick="toUrl('<%=dynamicDomain%>/user/page')">返回</button>
                                		</div>
									</td>
								</tr>
			                 </table>
			            </form>
			        </jdf:form>
				</div>
			</div>
		</div>
	</div>
	<jdf:tableLabelValidate domain="User"/>
	<script type="text/javascript">
		$(document).ready(function(){
			if($("#id").val()!=""){
				$(".pass").hide();
				$("#type").attr("colSpan","3");
				$("#resetPassaord").show();
			} else {
				$("#resetPassaord").hide();
			}
			$("#typeSelect option[value='10']").remove();
		});

		function intoResetPassword() {
			window.showModalDialog("<%=dynamicDomain%>/user/resetPassword/${entity.id}?ajax=1",'','dialogWidth=500px;dialogHeight=200px;resizable=no;help=no;center=yes;status=no;scroll=no;edge=sunken');
		}
		
		function prepare() {
            var companyIds = "";
            $('[name="company"]').each(function(){
                if($(this).attr("checked")){
                	companyIds += $(this).val() + ";";
                }
            });
            $("#companyIds").val(companyIds);
            var companyId1s = "";
            $('[name="company1"]').each(function(){
                if($(this).attr("checked")){
                	companyId1s += $(this).val() + ";";
                }
            });
            $("#companyId1s").val(companyId1s);
            var companyId2s = "";
            $('[name="company2"]').each(function(){
                if($(this).attr("checked")){
                	companyId2s += $(this).val() + ";";
                }
            });
            $("#companyId2s").val(companyId2s);
            var noticeTypes = "";
            $('[name="userNotice"]').each(function(){
                if($(this).attr("checked")){
                	noticeTypes += $(this).val() + ";";
                }
            });
            $("#noticeTypes").val(noticeTypes);
        }
	</script>
</body>
</html>